class UsersController < ApplicationController
	before_action :set_user, only: [:show, :edit, :update, :destroy]

  def index
  	if signed_in?
  		@users = User.all
  	else
  		redirect_to login_path, notice: "Please log in first to see all users"
  	end
  end

  def new
  	@user = User.new
  end

  def create
  	@user = User.new(user_params)
  	if @user.save
  		redirect_to login_path, notice: "New User Added. Please Log-in"
  	else
  		render action: "new"
  	end
  end

  def destroy
    @user.destroy
    redirect_to users_url
  end

  private

	def user_params
		params.require(:user).permit(:name, :email, :password, :password_confirmation)
	end

  	def set_user
    	@user = User.find(params[:id])
  	end

end
